package Persistance;

import Model.Book;

import java.util.ArrayList;

public class BookList {

    private ArrayList<Book> bookList;
    private ArrayList<Boolean> availabilityList;

    public BookList(){

        bookList = new ArrayList<Book>();
        availabilityList = new ArrayList<Boolean>();
        populateLists();
    }


    public int size(){
        return this.bookList.size();
    }

    public Book getBookWithID(int id){
        if(id >= 0 && id < this.bookList.size())
            return this.bookList.get(id);
        else
            return null;
    }

    public boolean getAvailabilityOfBook(int index){
        if(index >= 0 && index < this.bookList.size())
            return this.availabilityList.get(index);
        else
            return false;
    }

    public void setAvailabilityOfBook(int index, boolean availability){
        this.availabilityList.set(index,availability);
    }

    public String toString(int index){
        String out = this.bookList.get(index).getName();
        if(this.availabilityList.get(index))
            out += "\t\t- Available";
        else
            out += "\t\t- Reserved";
        return out;

    }

    private void populateLists() {
        for(int bookId = 1; bookId<11; bookId++){ // i am using this for loop just so that it is easy to populate this bookList.
            this.bookList.add(new Book("Book "+bookId));
            this.availabilityList.add(true);
        }
    }

}
